如題:
import os
hostname = str(input('請輸入要測試的網域: '))
#將輸出結果存放到當前目錄的response.txt並在後面cat出
#ping -count 傳送封包4次
response = os.system("ping -c 4 %s" %(hostname)+ "> response.txt")
#這裡如果有回應response將會呈現為狀態0
if response == 0:
print(hostname, 'is working!')
os.system("cat response.txt")
else:
print(hostname, 'is down!')